package com.toilet.easyvideofx.global;


import javafx.scene.control.Alert;
import javafx.stage.Stage;

/**
 * 全局异常
 */
public class GlobalException {
    /**
     * 主窗口
     */
    private final Stage primaryStage;

    public GlobalException(Stage primaryStage) {
        // 捕捉未处理的异常
        Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
            System.out.println(throwable);
            Alert exceptionAlert = new Alert(Alert.AlertType.ERROR);
            exceptionAlert.setTitle("异常信息");
            exceptionAlert.setHeaderText(null);
            // 展示异常信息
            exceptionAlert.setContentText(throwable.getMessage());
            exceptionAlert.initOwner(primaryStage);
            exceptionAlert.showAndWait();
        });
        this.primaryStage = primaryStage;
    }


}
